<?php
include("../includes/common.php");
if($islogin2==1){}else exit("<script language='javascript'>window.location.href='./login.php';</script>");
include './head.php';
?>
<?php
function do_callback($data){
	global $DB,$userrow;
	if($data['status']>=1)$trade_status='TRADE_SUCCESS';
	else $trade_status='TRADE_FAIL';
	$array=array('pid'=>$data['pid'],'trade_no'=>$data['trade_no'],'out_trade_no'=>$data['out_trade_no'],'type'=>$data['type'],'name'=>$data['name'],'money'=>$data['money'],'trade_status'=>$trade_status);
	$arg=argSort(paraFilter($array));
	$prestr=createLinkstring($arg);
	$urlstr=createLinkstringUrlencode($arg);
	$sign=md5Sign($prestr, $userrow['key']);
	if(strpos($data['notify_url'],'?'))
		$url=$data['notify_url'].'&'.$urlstr.'&sign='.$sign.'&sign_type=MD5';
	else
		$url=$data['notify_url'].'?'.$urlstr.'&sign='.$sign.'&sign_type=MD5';
	return $url;
}
if(!empty($_GET['type']) && !empty($_GET['kw'])) {
	$kw=daddslashes($_GET['kw']);
	if($_GET['type']==1)$sql=" and trade_no='$kw'";
	elseif($_GET['type']==2)$sql=" and out_trade_no='$kw'";
	elseif($_GET['type']==3)$sql=" and name='$kw'";
	elseif($_GET['type']==4)$sql=" and money='$kw'";
	elseif($_GET['type']==5)$sql=" and type='$kw'";
	else $sql="";
	$link='&type='.$_GET['type'].'&kw='.$_GET['kw'];
}else{
	$sql="";
	$link='';
}
$uid=$rs=$DB->query("select * from pay_user WHERE name={$pid}");
 
foreach($uid as $res){
 $usid=$res['id'];
}

$numrows=$DB->query("SELECT count(*) from pay_order WHERE pid={$usid}{$sql}")->fetchColumn();
$pagesize=25;
$pages=intval($numrows/$pagesize);
if ($numrows%$pagesize)
{
 $pages++;
 }
if (isset($_GET['page'])){
$page=intval($_GET['page']);
}
else{
$page=1;
}
$offset=$pagesize*($page - 1);

$list=$DB->query("SELECT * FROM pay_order WHERE pid={$usid}{$sql} order by trade_no desc limit $offset,$pagesize")->fetchAll();

?>			            

<div class="clearfix"></div>
  <div class="content-wrapper">
    <div class="container-fluid">  
     <div class="row pt-2 pb-2">
        <div class="col-sm-9">
            <h4 class="page-title">订单记录</h4>
            <ol class="breadcrumb">
            <li class="breadcrumb-item"><a href="javaScript:void();">订单</a></li>
            <li class="breadcrumb-item"><a href="javaScript:void();">列表</a></li>
            <li class="breadcrumb-item active" aria-current="page">信息</li>
         </ol>
       </div>
      </div>
     </div>

 <div class="row">
        <div class="col-lg-12">
          <div class="card">
            <div class="card-header"><i class="fa fa-table"></i>订单记录&nbsp; <span class="badge badge-pill badge-danger m-1"><?php echo $numrows?></span>
            </div>
            <div class="col-lg-6">
            <form action="order.php" method="GET">
         <div class="input-group">
                  <select class="input-sm form-control" name="type">
                                    <option value="1">交易号</option>
                                    <option value="2">商户订单号</option>
                                    <option value="3">商品名称</option>
                                    <option value="4">商品金额</option>
                                    <option value="5">支付方式</option>
                                  </select>           
                            <div class="col-lg-6">
                            <input class="form-control" name="kw" placeholder="搜索内容" type="text">
                            </div> 
                  <div class="input-group-append">
                    <button class="btn btn-dark"  type="submit">搜索</button>
                  </div>
                  </div>
                  </form>
                </div>
            <div class="card-body">
              <div class="table-responsive">

              <table id="default-datatable" class="table table-bordered">
                <thead>
                    <tr>
                        <th>交易号/商户订单号</th>
                                <th>商品名称</th>
                                <th>商品金额</th>
                                <th>支付方式</th>
                                <th>创建时间/完成时间</th>
                                <th>状态</th>
                                <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    
                       <?php
                 foreach($list as $res){
              echo '<tr><td>'.$res['trade_no'].'<br/>'.$res['out_trade_no'].'</td><td>'.$res['name'].'</td><td>￥ <b>'.$res['money'].'</b></td><td> <b>'.$res['type'].'</b></td><td>'.$res['addtime'].'<br/>'.$res['endtime'].'</td><td>'.($res['status']==1?'<span class="badge badge-pill badge-secondary shadow-secondary m-1">已完成</span>':'<span class="badge badge-pill badge-danger shadow-danger m-1">未完成</span>').'</td><td>'.($res['status']==1?'<a href="'.do_callback($res).'" title="支付通知" target="_blank" rel="noreferrer"><span class="badge badge-pill badge-secondary shadow-secondary m-1">重新通知</span><a/>':'<span class="badge badge-pill badge-danger shadow-danger m-1">禁止回调</span>').'</td></tr>';
                  }
                  ?>
                  
                    </tbody>
                    </table>
           </div>
      </div>
</div>
</div>
</div>
<?php
echo'<ul class="pagination pagination-separate pagination-round pagination-sm">';
$first=1;
$prev=$page-1;
$next=$page+1;
$last=$pages;
if ($page>1)
{
echo '<li class="page-item"><a class="page-link" href="order.php?page='.$first.$link.'">首页</a></li>';
echo '<li class="page-item"><a class="page-link" href="order.php?page='.$prev.$link.'">&laquo;</a></li>';
} else {
echo '<li class="page-item"><a class="page-link">首页</a></li>';
echo '<li class="page-item"><a class="page-link">&laquo;</a></li>';
}
for ($i=1;$i<$page;$i++)
echo '<li class="page-item"><a class="page-link" href="order.php?page='.$i.$link.'">'.$i .'</a></li>';
echo '<li class="page-item"><a class="page-link">'.$page.'</a></li>';
if($pages>=10)$sss=$page+10;else $sss=$pages;
for ($i=$page+1;$i<=$sss;$i++)
echo '<li class="page-item"><a class="page-link" href="order.php?page='.$i.$link.'">'.$i .'</a></li>';
echo '';
if ($page<$pages)
{
echo '<li class="page-item"><a class="page-link" href="order.php?page='.$next.$link.'">&raquo;</a></li>';
echo '<li class="page-item"><a class="page-link" href="order.php?page='.$last.$link.'">尾页</a></li>';
} else {
echo '<li class="page-item"><a class="page-link">&raquo;</a></li>';
echo '<li class="page-item"><a class="page-link">尾页</a></li>';
}
echo'</ul>';
#分页
?>
</div>
    </div>
        </div>
      </div>
    </div>
    </div>
    <a href="javaScript:void();" class="back-to-top"><i class="fa fa-angle-double-up"></i> </a>
    
  </div>
  <script src="/user/kuyun/plugins/bootstrap-datatable/js/jquery.dataTables.min.js"></script>
  <script src="/user/kuyun/plugins/bootstrap-datatable/js/dataTables.bootstrap4.min.js"></script>
  <script src="/user/kuyun/plugins/bootstrap-datatable/js/dataTables.buttons.min.js"></script>
  <script src="/user/kuyun/plugins/bootstrap-datatable/js/buttons.bootstrap4.min.js"></script>
  <script src="/user/kuyun/plugins/bootstrap-datatable/js/jszip.min.js"></script>
  <script src="/user/kuyun/plugins/bootstrap-datatable/js/pdfmake.min.js"></script>
  <script src="/user/kuyun/plugins/bootstrap-datatable/js/vfs_fonts.js"></script>
  <script src="/user/kuyun/plugins/bootstrap-datatable/js/buttons.html5.min.js"></script>
  <script src="/user/kuyun/plugins/bootstrap-datatable/js/buttons.print.min.js"></script>
  <script src="/user/kuyun/plugins/bootstrap-datatable/js/buttons.colVis.min.js"></script>


  <?php include 'foot.php';?>


